package cn.kshost.zqyg.manager.demo;

import cn.kshost.zqyg.manager.listener.ExcelListener;
import cn.kshost.zqyg.model.vo.product.CategoryExcelVo;
import com.alibaba.excel.EasyExcel;

import java.util.ArrayList;

public class EasyExcelDemo {
    public static void main(String[] args) {
        //读excel
//        excelReadDemo();
        //写excel
//        writeExcleDemo();
    }
    private static void writeExcleDemo() {
        //定义输出文件路径
        String filePath = "E:\\javavideo\\test\\day07\\资料\\分类数据yws.xlsx";
        //创建数据
        ArrayList<CategoryExcelVo> categoryExcelVos = new ArrayList<>();
        categoryExcelVos.add(new CategoryExcelVo(1l,"小米手机","www.baidu.com",2L,0,1));
        categoryExcelVos.add(new CategoryExcelVo(2l,"HAUW手机","www.huawei.com",2L,0,2));
        categoryExcelVos.add(new CategoryExcelVo(3l,"爱风手机","www.apple.com",3L,1,2));
        //写入数据
        EasyExcel.write(filePath, CategoryExcelVo.class).sheet("手机分类").doWrite(categoryExcelVos);
        System.out.println("写入成功");
    }
    private static void excelReadDemo() {
        //文件路径
        String filePath = "E:\\javavideo\\test\\day07\\资料\\01.xlsx";
        //创建监听器
        ExcelListener<CategoryExcelVo> excelListener = new ExcelListener<>();

        //读取Excel数据
        EasyExcel.read(filePath, CategoryExcelVo.class, excelListener).sheet().doRead();
        //遍历数据
        for (CategoryExcelVo categoryExcelVo : excelListener.getDataList()) {
            System.out.println(categoryExcelVo);
        }
    }
}
